package fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.wangjin.menu.AssignmentDetailActivity;
import com.example.wangjin.menu.R;

import org.apache.http.impl.HttpConnectionMetricsImpl;

/**
 * Created by wangjin on 15/6/17.
 */
public class ProjectAssignmentFragment extends Fragment {

    private String[] ass = {"HCI原型设计","HCI程序设计", "HCI期末答辩"};

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.project_assignment_layout,container,false);
        ListAdapter l = new ListAdapter(ass);
        ListView lv = (ListView) v.findViewById(R.id.listView);
        lv.setAdapter(l);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent i = new Intent(getActivity(), AssignmentDetailActivity.class);
                startActivity(i);

            }
        });
        return v;
    }

    class ListAdapter extends ArrayAdapter<String>{

        private String[] ass;

        public ListAdapter(String[] ass){
            super(getActivity(),0,ass);
            this.ass = ass;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView == null){
                convertView = getActivity().getLayoutInflater().inflate(R.layout.project_ass_item,null);
                TextView t = (TextView) convertView.findViewById(R.id.textView12);
                t.setText(ass[position]);
                return convertView;
            }else {
                return convertView;
            }
        }
    }


}
